package com.yanzhang.service.role;

import com.yanzhang.dao.role.RoleDao;
import com.yanzhang.dao.role.RoleDaoImpl;
import com.yanzhang.pojo.Role;
import com.yanzhang.util.DBUtil;
import org.junit.Test;

import java.sql.Connection;
import java.util.List;

/**
 * @author yanzhang
 */
public class RoleServiceImpl implements RoleService{

    private RoleDao roleDao;

    public RoleServiceImpl() {
        roleDao = new RoleDaoImpl();
    }

    /**
     * 获取角色列表
     * @return 角色集合
     */
    @Override
    public List<Role> getRoleList() {
        List<Role> roleList = null;
        Connection connection = DBUtil.getConnection();
        try {
            roleList = roleDao.getRoleList(connection);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBUtil.closeConnection(connection);
        }
        return roleList;
    }

    @Test
    public void testGetRoleList() {
        List<Role> roleList = getRoleList();
        for (Role role : roleList) {
            System.out.println(role);
        }
    }
}
